import React, { Component } from "react";
import "./index.css";

export default class Footer extends Component {
  clearHanler = () => {
    this.props.clearChecked();
  };
  changeAll = (event) => {
    this.props.changeAllStatus(event.target.checked)
  };
  render() {
    const { todos } = this.props;
    // 计算已完成的
    const checkedNum = todos.reduce(
      (pre, current) => pre + (current.done ? 1 : 0),
      0
    );

    return (
      <div className="todo-footer">
        <label>
          <input
            type="checkbox"
            checked={checkedNum == todos.length && todos.length  ? true : false}
            onChange={this.changeAll}
          />
        </label>
        <span>
          <span>已完成{checkedNum}</span> / 全部{todos.length}
        </span>
        <button className="btn btn-danger" onClick={this.clearHanler}>
          清除已完成任务
        </button>
      </div>
    );
  }
}
